home *** CD-ROM | disk | FTP | other *** search
- /*
- File: PlatfMem.h
-
- Contains: Platform layer interfaces
-
- Owned by: Jens Alfke
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <5> 10/9/96 JP 1394963: Fixed for 68K
- <4> 9/19/96 DH Task: low memory changes, 1377922, 1377888.
- Added/modified thresholds for low/out-of
- memory.
- <3> 9/13/96 jpa 1371387: Speed optimizations.
-
- To Do:
- In Progress:
-
- */
-
- #ifndef _PLATFMEM_
- #define _PLATFMEM_
-
- #ifndef _MEMCNFIG_
- #include "MemCnfig.h"
- #endif
-
- #ifndef _MEMMGR_
- #include <MemMgr.h>
- #endif
-
- #include <stddef.h>
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
-
- //========================================================================================
- // Defines
- //========================================================================================
-
- #ifndef __MWERKS__
- #define _FIL_ "" /* MPW puts entire pathnames in; yuk! */
- #else
- #define _FIL_ __FILE__
- #endif
-
- #define MM_ASSERT(condition) \
- if(!MM_DEBUG || (condition)) ; else MM_ASSERT_FAILED( #condition, _FIL_ )
-
- #define MM_WARN \
- if(!MM_DEBUG) ; else MM_SHOW_WARNING
-
- #define MM_WARN_COALESCE \
- if(!MM_DEBUG_COALESCE) ; else MM_SHOW_WARNING
-
- #define MM_PRINTING 0 // Set to 1 to enable MM_PRINT
-
- #define MM_PRINT if( !MM_PRINTING ) ; else somPrintf
-
-
- //========================================================================================
- // Types
- //========================================================================================
-
- typedef unsigned long MMULong;
-
- typedef unsigned long mmboolean;
- // Better to use 32-bit booleans for code optimization. Can't change MMBoolean since it's
- // in the public API, but we can use this new type internally.
-
- #ifdef __xlC
- typedef unsigned long SIZE_T;
- #else
- typedef size_t SIZE_T;
- #endif
-
- typedef unsigned long ODBytePtr;
- typedef unsigned long ODBlockSize;
-
-
-
-
- //========================================================================================
- // Constants
- //========================================================================================
-
- const mmboolean kMMFalse = 0;
- const mmboolean kMMTrue = 1;
-
- #define kMMNULL (0)
-
- const size_t kPlatformMinFreeSpace = 64 * 1024; // Leave this much free.
- const size_t kPlatformMinContigSpace = 32 * 1024; // Leave this size block available
- // Free space is low. Allocations restricted.
- const size_t kPlatformLowTotalSpace = 128 * 1024;
- const size_t kPlatformLowContigSpace = 64 * 1024;
- // Fraction of free space allowed to be allocated when space is low
- const size_t kMinFreeRatio = 1/8;
-
-
- //========================================================================================
- // Global function declarations
- //========================================================================================
-
- // Declare somPrintf w/o having to include all those SOM headers:
- #if PRAGMA_IMPORT_SUPPORTED
- #pragma import on
- #endif
- extern "C" int somPrintf (const char * fmt, ...); // From <som.xh>
- #if PRAGMA_IMPORT_SUPPORTED
- #pragma import off
- #endif
-
- void PlatformZapMem( void *start, size_t size, MMULong value );
- void *PlatformAllocateBlock(size_t size, MMHeapLocation);
- void PlatformFreeBlock(void *ptr);
-
- void MM_ASSERT_FAILED(const char *cond, const char *fil);
- void MM_SHOW_WARNING(const char *msg, ...);
-
- //----------------------------------------------------------------------------------------
- // PlatformCopyMemory
- //----------------------------------------------------------------------------------------
-
- inline void PlatformCopyMemory(void *source, void *destination, size_t length)
- {
- BlockMoveData(source, destination, (Size) length);
- }
-
- #if MM_DEBUG
-
- #define LOWEST_POSSIBLE_ADDRESS() ((void*) &SystemZone()->heapData)
- #define HIGHEST_POSSIBLE_ADDRESS() ((void*) gTotalMemory)
-
- extern size_t gTotalMemory;
-
- #endif
-
- #endif
-